function debounce(func, delay) {  
  let timeout;  
  return function() {  
    const context = this;  
    const args = arguments;  
    clearTimeout(timeout);  
    timeout = setTimeout(() => {  
      func.apply(context, args);  
    }, delay);  
  };  
}  
  
// 创建防抖自定义指令  
const debounceDirective = {  
  mounted(el, binding) {  
    const { value, arg } = binding;  
    el.addEventListener(arg || 'click', debounce(value, binding.modifiers.delay || 2000)); // 假设默认事件为 click，默认防抖时间为 200ms  
  },  
  // unmounted(el, binding) {  
  //   const { arg } = binding;  
  //   el.removeEventListener(arg || 'click');  
  // },  
  updated(el, binding) {  
    // 当绑定的值变化时，需要重新绑定事件监听器  
    this.unmounted(el, binding);  
    this.mounted(el, binding);  
  }  
};  
  
export default debounceDirective;